package com.ezcoding.common;

import com.ezcoding.controller.*;
import com.ezcoding.model._MappingKit;
import com.jfinal.config.*;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;

public class ServerConfig extends JFinalConfig {
    @Override
    public void configConstant(Constants constants) {
        PropKit.use("config.properties");
        constants.setDevMode(PropKit.getBoolean("devMode"));
        constants.setBaseDownloadPath(PathKit.getWebRootPath() + "/download");
    }

    @Override
    public void configRoute(Routes routes) {
        routes.add("/", IndexController.class);
        routes.add("/user", UserController.class);
        routes.add("/company", CompanyController.class);
        routes.add("/product", ProductController.class);
        routes.add("/userRelation", UserRelationController.class);
        routes.add("/dingdan", DingdanController.class);
        routes.add("/message", MessageController.class);
        routes.add("/finance",FinanceController.class);
        routes.add("/trade",TradeController.class);
    }

    @Override
    public void configEngine(Engine engine) {

    }

    @Override
    public void configPlugin(Plugins plugins) {
        DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password"));

        plugins.add(druidPlugin);

        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);

        arp.setBaseSqlTemplatePath(PathKit.getWebRootPath());

        arp.addSqlTemplate("sql/user.sql");
        arp.addSqlTemplate("sql/company.sql");
        arp.addSqlTemplate("sql/product.sql");
        arp.addSqlTemplate("sql/formula.sql");
        arp.addSqlTemplate("sql/user_relation.sql");
        arp.addSqlTemplate("sql/dingdan.sql");
        arp.addSqlTemplate("sql/message.sql");
        arp.addSqlTemplate("sql/finance.sql");
        arp.addSqlTemplate("sql/trade.sql");

        _MappingKit.mapping(arp);

        plugins.add(arp);
    }

    @Override
    public void configInterceptor(Interceptors interceptors) {

    }

    @Override
    public void configHandler(Handlers handlers) {
        //创建上下文
        handlers.add(new ContextPathHandler("ctx"));
    }
}
